#! /bin/bash

# (c) Michael Goetze, 2011, mgoetze@mgoetze.net
# (c) Thomas Lange 2014

error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code
if ifclass JDK_EL7 ; then

#install Oracle JDK8
$ROOTCMD cd /root
$ROOTCMD wget http://faiserver/jdk-8u161-linux-x64.rpm
$ROOTCMD rpm -i jdk-8u161-linux-x64.rpm
#jdbc mysql 5.6 need >= 5.1.38
#install depend only
#$ROOTCMD yum install -y mysql-connector-java && $ROOTCMD yum remove -y mysql-connector-java
#$ROOTCMD wget http://faiserver/mysql-connector-java-5.1.46-bin.jar
#$ROOTCMD mkdir /usr/share/java
#$ROOTCMD cp -f mysql-connector-java-5.1.46-bin.jar /usr/share/java/mysql-connector-java.jar

cat << 'EOF' > $target/etc/profile.d/java.sh
#set java environment
JAVA_HOME=/usr/java/jdk1.8.0_161
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
EOF

#disable transparent_hugepage 
ainsl /etc/rc.local 'echo never > /sys/kernel/mm/transparent_hugepage/defrag'
ainsl /etc/rc.local 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'

fi

exit $error
